/** 
 * Copyright 2010 Erlacher Felix, Estgfaeller Wolfgang, Ferula Patrick
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package at.socialconference.app;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import at.socialconference.app.model.ATalk;
import at.socialconference.app.model.AUser;

public class PeopleList extends ListActivity{


	private AUser[] users;

	public String[] getListItems(){

		if(users!=null){
			String[] si = new String[users.length];
			for(int i=0;i<users.length;i++){
				AUser u = users[i];

				String tmp = u.getTitle()==null?"":u.getTitle()+" ";
				tmp += u.getFirstname()==null?"":u.getFirstname()+" ";
				tmp += u.getLastname()==null?"":u.getLastname()+"";
				si[i]= tmp;
			}
			return si;
		}
		return new String[0];
	}


	public void onCreate(Bundle savedInstanceState) {
		Bundle b = getIntent().getExtras();
		Object o = b.getParcelable("person");

		if (o!=null){
			users = ((AUser)o).getContactArray();
		}else{
			o = b.getParcelable("talk");
			if (o!=null){
				users = ((ATalk)o).getaSpeakers();
			}
		}

		super.onCreate(savedInstanceState);
		setContentView(R.layout.listview);
		ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, getListItems());
		this.setListAdapter(arrayAdapter);

	}

	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		AUser o = users[position];
		Bundle b = new Bundle();
		b.putParcelable("person", o); 
		Intent i = new Intent(this, PeopleActivity.class); 
		i.putExtras(b);
		startActivity(i);

	}
}
